package com.yyj.controller;

import com.yyj.entity.Calendar;
import com.yyj.entity.Result;
import com.yyj.service.CalendarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/calendar")
public class CalendarController {
    @Autowired
    private CalendarService calendarService;

    //查询所有
    @GetMapping("/{userId}")
    private Result getCalender(@PathVariable Integer userId) {
        List<Calendar> list = calendarService.getCalendar(userId);
        return Result.success(list);
    }

    //点击添加日期会把这个格子里的所有数据显示出来(根据date查询)
    @PostMapping("/setCalendar")
    public Result getByDate(@RequestBody Calendar calendar) {
        Calendar list = calendarService.getByDate(calendar);
        return Result.success(list);
    }

    //新增和更新
    @PostMapping("/saveCalendar")
    private Result saveCalendar(@RequestBody Calendar calendar) {
        calendarService.saveCalendar(calendar);
        return Result.success();
    }
}
